package com.adu.springbootdemo.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.adu.springbootdemo.domain.DbConnectInfo;
// https://www.runoob.com/w3cnote/jdbc-use-guide.html
public class DbUtil {
   
    public static Connection getConnection(DbConnectInfo dbConnectInfo){
       
        String URL = "jdbc:mysql://"+dbConnectInfo.Ip+":3306/"+dbConnectInfo.DbName+"?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8";
        String USER = dbConnectInfo.User;
        String PASSWORD =dbConnectInfo.Password;
        Connection conn = null;
        try {
            //1.加载驱动程序
            Class.forName("com.mysql.jdbc.Driver");
            //2. 获得数据库连接
             conn = DriverManager.getConnection(URL, USER, PASSWORD);
         } catch (ClassNotFoundException e) {
            e.printStackTrace();
         } catch (SQLException e) {
            e.printStackTrace();
        }

        return conn;
    }
}
